import { setDatas } from '../../../_resource/common/modules/JiessTable/utils.js';
export default (hook, { Table }) => {
	return {
		isJiess: true,
		name: 'ProTable',
		setup({ midder, update, primaryKey }) {
			const { table, proxy } = midder;
			const { $reactive, $watchEffect } = hook.$m;
			const data = (table.datas = $reactive([], 2));
			const columns = (table.columns = $reactive([], 2));
			// ============================================
			$watchEffect(() => setDatas(proxy.datas, data, primaryKey));
			$watchEffect(() => {
				setDatas(
					proxy.columns.filter((item) => !item.hidden),
					columns,
				)
			});
			table.reload = () => update?.call(this, midder);
			// ===========================================
			this.add({
				is: Table,
				pagination: false,
				style: { width: '100%' },
				dataSource: { $proxy: data, warn: false },
				columns: { $proxy: columns, warn: false },
				...table.tableProps,
			});
		},
	};
}